import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, INFO_SOURCE, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY, BUSINESS_DATA, REGISTERED_CAPITAL, CellRenderMap } from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      title: '披露日期',
      field: 'noticeDate',
      width: 100,
      align: 'center',
      sortable: true
    },
    { ...INFO_SOURCE('dataSource'), width: 200 },
    {
      title: '许可证编号',
      field: 'certificateNumber',
      width: 150,
      align: 'center',
      sortable: true,
      cellRender:{ name: CellRenderMap.HighLight }
    },
    {
      title: '变动类别',
      field: 'changeTypeCode',
      width: 150,
      align: 'center',
      sortable: true
    },
    {
      title: '许可阶段',
      field: 'approvalStageCode',
      width: 150,
      align: 'center',
      sortable: true
    },
    {
      title: '发证机关',
      field: 'issuingDepartment',
      width: 220,
      align: 'center',
      sortable: true
    },
    {
      title: '有效起止日期',
      width: 250,
      field: 'periodOfValidityStartDate',
      align: 'center',
      sortable: true,
      slots: {
        default({ row }) {
          const showText = row.isExpired !== null ? (row.isExpired ? '过期' : '有效') : '';
          const className = 'revocation ' + 'revocation-' + row.isExpired;
          const isEmpty = row.periodOfValidityStartDate || row.periodOfValidityExpirationDate;

          return (
            <span>
              {isEmpty ? (
                <span>
                  {row.periodOfValidityStartDate || '-'} 至 {row.periodOfValidityExpirationDate || '-'}
                </span>
              ) : (
                '-'
              )}
              {showText ? (
                <span title={showText} class={className}>
                  {showText}
                </span>
              ) : (
                ''
              )}
            </span>
          );
        }
      }
    },
    {
      title: '危险废物经营方式',
      width: 210,
      field: 'businessMode',
      showOverflow: 'title'
    },
    {
      title: '经营危险废物类别',
      field: 'hazardousWasteClassCode',
      width: 210,
      showOverflow: 'title'
    },
    {
      title: '经营危险废物代码',
      field: 'hazardousWasteCode',
      width: 210,
      showOverflow: 'title'
    },
    {
      title: '核准经营规模',
      field: 'operatingScale',
      align: 'center',
      width: 210,
      showOverflow: 'title'
    },
    {
      title: '设施地址',
      field: 'address',
      width: 230,
      showOverflow: 'title'
    },
    {
      title: '联系人',
      width: 120,
      field: 'contactPerson',
      align: 'center'
    },
    {
      title: '联系方式',
      width: 120,
      field: 'contactPhoneNumber',
      align: 'center'
    },
    { ...PROVINCE },
    { ...CITY },
    { ...COUNTRY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    columns
  };
}
